var xml2js = require("xml2js");
// let parseString = xml2js.parseString;

function stripRootElement(obj) {
  if (Object.keys(obj).length > 1){
    return obj;  // 有多个属性，则表示该obj没有rootElement，直接返回即可
  }
  const childrenElement = obj[Object.keys(obj)[0]];

  return childrenElement;
}

let m = function(xml, stripRoot=false) {
    let json = "";
    let parser = new xml2js.Parser({
        explicitArray: false,
        attrkey: "attr0123",
        charkey: "value0123"
    });
    parser.parseString(xml, function (err, result) {
        json = result;
    });
    if (stripRoot){
      return stripRootElement(json);
    } else {
      return json;
    }
};

module.exports = m;